package com.lc.service.impl;

import com.lc.bean.Menu;
import com.lc.dao.MenuDao;
import com.lc.dao.impl.MenuDaoImpl;
import com.lc.service.MenuService;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: ManolinCoder
 * @time: 2021/8/25
 */
public class MenuServiceImpl implements MenuService {
    private MenuDao menuDao = new MenuDaoImpl();
    @Override
    public List<Menu> getMenuList() {
        //在service层进行菜单的分级
        List<Menu> menuList = menuDao.getMenuList();//此时菜单未分级
        List<Menu> newMenuList = new ArrayList<>();//保存分级后的菜单
        for (Menu menu : menuList) {
            if (menu.getUpmenuId()==0){//说明是一级菜单
                List<Menu> secondList = new ArrayList<>();
                for (Menu second : menuList) {
                    if (second.getUpmenuId()==menu.getMenuId()){//说明是这一类的二级菜单
                        secondList.add(second);
                    }
                }
                menu.setSecondMenuList(secondList);
                newMenuList.add(menu);
            }
        }

        return newMenuList;
    }
}
